package net.zjitc.servlet;

import com.google.gson.Gson;
import net.zjitc.domain.User;
import net.zjitc.utils.Msg;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author admin
 * @Date 2019/3/7 8:18
 */
@WebServlet(name = "JsonCheckServlet",urlPatterns = "/Jsoncheck")
public class JsonCheckServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        User user = new Gson().fromJson(request.getReader(),User.class);
        String username = user.getUsername();

        Msg msg = new Msg();
        if(username.equals("admin")){
            msg.setMsg("false");
        }else{
            msg.setMsg("true");
        }
        String info = new Gson().toJson(msg);
        response.getWriter().print(info);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
